package cn.wonderland.controller;

import cn.wonderland.domain.Floor;
import cn.wonderland.service.BuildService;
import cn.wonderland.util.JSONResult;
import cn.wonderland.vo.BuildVo;
import cn.wonderland.vo.DeviceListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/build")
public class BuildController {

    @Autowired
    private BuildService buildService;

    /*
    * 批量新建楼层信息
    * */
    @PostMapping("/addFloor")
    public JSONResult<List<Floor>> addFloor(@RequestBody List<Floor> floors) {
        if (floors == null || floors.isEmpty()) {
            return JSONResult.<List<Floor>>builder().message("参数不能为空！").data(null)
                    .code("500").success(false).build();
        }
        buildService.addFloor(floors);
        return JSONResult.<List<Floor>>builder().message("请求成功").code("200")
                .data(null).success(true).build();
    }

    /*
    * 根据楼宇id查询设备
    * getDeviceListByBuildId
    * */
    @GetMapping("/getDeviceListByBuildId")
    public JSONResult<BuildVo> getDeviceListByBuildId(@RequestParam Integer id){
        return buildService.getDeviceListByBuildId(id);
    }

    /*
     * 根据设备类型  查找所有的设备
     * getDeviceListByDeviceType
     */
    @GetMapping("/getDeviceListByDeviceType")
    public JSONResult<List<DeviceListVo>> getDeviceListByDeviceType(@RequestParam Integer type){
        return buildService.getDeviceListByDeviceType(type);
    }
}
